using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;

namespace Ghasam.Business.DAO.Impl
{
    public class StockDao :DaoBase<Stock>,IStockDao
    {
        public IList<Stock> FindStock(string name, string binnumber, string serial, int? status, DateTime? importdate)
        {
            string query = "(1=1)";

            if (name.Length > 0)
            {
                query += " AND Stock.StockName LIKE '"+ name +"%'";
            }

            if (binnumber.Length > 0)
            {
                query += " AND Stock.BinNumber='" + binnumber+"'";
            }

            if (serial.Length > 0)
            {
                query += " AND Stock.Serial='" + serial + "'";
            }
            
            if (status.HasValue && status >0 )
            {
                query += " AND Stock.StockStatus.Id=" + status.Value;
            }

            if (importdate.HasValue)
            {
                query += " AND Stock.ImportDate='" + importdate.Value+"'";
            }

            return base.HibernateTemplate.Find<Stock>("from Stock as Stock Where " + query);
        }
        public IList<Stock> FindOrderPoint()
        {
            return HibernateTemplate.Find<Stock>("from Stock as stock where stock.OrderPoint > stock.Quantity");
        }
    }
}
